package hw_7_25.filterKeyword;

import java.util.Arrays;
import java.util.List;
import java.util.regex.Pattern;

public class FilterKeyword_Pattern {

    public static void main(String[] args) {
        List<String> sensitiveWords = Arrays.asList("性", "色情", "爆炸", "恐怖", "枪", "军火");
        String content = "在网络程序中，如“性”、“色情”、“爆炸”、“恐怖”、“枪”、“军火”等，女性，男性这些都不可以在网上进行传播，需要过滤掉或者用其他词语替换掉。";
        String newStr = filterSensitiveWord(sensitiveWords,content);
        System.out.println(newStr);
    }

    private static String filterSensitiveWord(List<String> sensitiveWords,String content) {
        for (String word : sensitiveWords) {
            String replacement = "*".repeat(word.length());
            content = content.replaceAll(Pattern.quote(word),replacement);
        }
        return content;
    }
}
